package com.green.cloud.api.web;

import com.green.cloud.server.api.HelloService;
import com.green.cloud.server.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hello")
public class HelloController {

    private HelloService helloService;

    @Autowired
    public HelloController(HelloService helloService) {
        this.helloService = helloService;
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public User add(@RequestBody User user) {
        return helloService.add(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public User user(@RequestParam("id") Long id) {
        return helloService.user(id);
    }

    @RequestMapping(value = "/redis/get", method = RequestMethod.GET)
    public String redisGet(@RequestParam("key") String key) {
        return helloService.redisGet(key);
    }

    @RequestMapping(value = "/mongo/add", method = RequestMethod.POST)
    public User mongoAdd(@RequestBody User user) {
        return helloService.mongoAdd(user);
    }

    @RequestMapping(value = "/mongo/get", method = RequestMethod.GET)
    public List<User> mongoGet() {
        return helloService.mongoGet();
    }
}
